package com.example.hj.controller;

import com.example.hj.entity.Student;
import com.example.hj.service.IStudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * Created by HuangJian on 2019/5/28.
 */
@Controller
public class TtController {

    @Autowired
    private IStudentService studentService;

    @RequestMapping(value = "/tt")
//    @ResponseBody
    public String tt(Model model) {
        System.out.println("---------- ++++++= " );
        List<Student> list = studentService.selectStudentByClass();
        for (Student student:list) {
            System.out.println(student.getName()+"--------"+student.getId());
        }
        model.addAttribute("content", "hello");
        model.addAttribute("students", list);
        return "/tt";
    }

    @RequestMapping("/page1")
    public ModelAndView page1(HttpServletRequest request){
        String param = request.getParameter("p");
        HttpSession session=request.getSession();
        session.setAttribute("param",param);
        System.out.println("---------- page:"+param );
        Student student=studentService.getStudent();
        System.out.println("-----"+student.getId()+"："+student.getName());
        ModelAndView mav = new ModelAndView("/tt");
        mav.addObject("content", "hello");
        mav.addObject("student", student);
        return mav;
    }

    @RequestMapping("/page2")
    public ModelAndView page2(HttpServletRequest request){
        String param = request.getParameter("p");
        HttpSession session=request.getSession();
        session.setAttribute("param",param);
        System.out.println("---------- page:"+param );
        Student student=studentService.getStudent();
        System.out.println("-----"+student.getId()+"："+student.getName());
        ModelAndView mav = new ModelAndView("/page");
        mav.addObject("content", "hello");
        mav.addObject("student", student);
        return mav;
    }

}
